{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Use Python in Advanced Statistics\n",
    "\n",
    "*這個學期剛剛學完了概率論與數理統計，這好趁這個機會複習一下並複習一下 `python`*\n",
    "<br>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## Chapter One Probability \n",
    "\n",
    "### 隨機試驗與樣本空間（Random Experiment and Sample Space）\n",
    "\n",
    "#### 隨機試驗\n",
    "隨機試驗是概率論中一個基本的概念。概括的講，在概率論中把符合下面三個特點的試驗叫做隨機試驗：\n",
    "* 可以在向空的條件下重複進行；\n",
    "* 每次試驗的可能結果不只一個，並且事先明確試驗的所有可能結果；\n",
    "* 進行一次試驗之前不能確定哪一個結果會出現。\n",
    "\n",
    "隨機試驗有很多種，例如常出現的擲骰子，摸球，射擊等。所有的隨機試驗的結果可以分為兩類來表示：<br>\n",
    "* 數量化表示：射擊命中的次數，商場每個小時的客流量，每天經過某個收費站的車輛等，這個結果本事就是數字；\n",
    "* 非數量化表示：拋硬幣的結果（正面/反面），化驗的結果（陽性/陰性）等，這些結果是定型的，非數量化的。但是可以用示性函數來表示，例如可以規定正面（陽性）為$1$，反面為$0$，這樣就可以實現了非數量化結果的數量化。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 樣本空間（Sample Space）：\n",
    "\n",
    "* 隨機試驗的所有可能結果構成的集合。一般即為$S$（capital S）；\n",
    "* $S$ 中的元素$e$稱為樣本點（也可以叫基本事件）；\n",
    "* 事件是樣本空間的子集，同樣是一個集合。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 事件的關係\n",
    "* 事件的包含：$A \\subseteq B$;\n",
    "* 事件的相等：$A = B$;\n",
    "* 互斥事件（互不相容事件）：不能同時出現；\n",
    "* 事件的和（並）：$A cup B$\n",
    "* 事件的差： $A - B$,$A$發生，$B$不發生；\n",
    "* 對立事件（逆事件）：互斥，必須出現其中一個。\n",
    "\n",
    "<br>\n",
    "事件的運算性質就是集合的性質"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 頻率和概率\n",
    "\n",
    "#### 頻率：\n",
    "\n",
    "頻率是指$0～1$之間的一個實數，在大量重複試驗的基礎上給出了隨機事件發生可能性的估計。<br>\n",
    "概率的穩定性：在充分多次試驗中，事件的頻率總在一個定值附近擺動，而且，試驗次數越多擺動越小。這個性質叫做頻率的穩定性。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 概率：\n",
    "\n",
    "概率的統計性定義：當試驗次數增加時，隨機時間$A$發生的頻率的穩定值為$p$就稱為概率。記為$P(A) = P$<br>\n",
    "概率的公理化定義：設隨機試驗對於的樣本空間為$S$。對每一個事件$A$，定義為$P(A)$，滿足：<br>\n",
    "1. 非負性：$P(A) \\geq 0$;\n",
    "2. 規範性：$P(S) = 1;\n",
    "3. 可列可加性：$A_1, A_2, \\dots 兩兩互斥，及$A_iA_j = \\oslash, i \\neq j$則 $P(\\cup A_i) = \\sum P(A_i)$ "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 條件概率（Conditional Probability）:\n",
    "$P(A|B)$表示在事件$B$發生的條件下，事件$A$發生的概率，相當於$A$在$B$所佔的比例。此時，樣本空間從原來的完整樣本空間$S$縮小到了$B$，由於有了條件的約束（事件$B$），使得原本的樣本空間減少了。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面我們可以通過韋恩圖做示例：<br>\n",
    "plot one：條件概率的樣本空間；<br>\n",
    "plot two：條件概率應如何計算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPQAAAC9CAYAAACEeFBaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29md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70Ptdee+17JSUlK1taWk74GGpra6vHjx+/KN22WCx2VHuUUpcrpW5J8/ljSqlKI+aeUUqNUUoVK6VKlVJlSqmpSqmHnLYr13FFgoPRo0dXz507t2DEiBGumaDx5ptvlr7wwgu7lFJmPShDzuAKD11fX99SV1fnmrWKo9EodXV1cXSKHIMhZ3CFoCORSHjjxo3dW7dudXyp02g0yurVq0v37NnTlIm50AaDnbgiKKaUiolIbTQardq8eXNJZWUlfr/fVjHF43FpbW2Vuro6du3a1djU1HTAzvINhkzgijZ0MqLT5frKy8ttXa2hq6srHolEYkBEHcNCbwaDG3GdoA0Gw4njija0wWDIDEbQBkMeYQRtMOQR/x84Y/gpkeasMgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x114914e10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "import sympy\n",
    "\n",
    "\n",
    "from matplotlib_venn import venn3, venn3_circles\n",
    "plt.figure(figsize=(4,4))\n",
    "v = venn2(subsets=(2,2,1), set_labels = ('A', 'B'))\n",
    "\n",
    "\n",
    "\n",
    "plt.title(\"Sample Venn diagram - plot one\")\n",
    "plt.annotate('P(AB)', xy=v.get_label_by_id('11').get_position() - np.array([0, 0.05]), xytext=(-70,-70),\n",
    "             ha='center', textcoords='offset points', bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),\n",
    "             arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.5',color='gray'))\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPQAAAC9CAYAAACEeFBaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi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iJp9NU3u1NTUXuHh4TO++eabf9cWbrMdcjqdTU/kwInE7J7TnQJ8qpRaC+wExp/uyTYwvhSRQqAIuBh4Smd//B5/qKErpkyZMrTuGzk5ORVKqdqA+p988klHl8vVKiMjY0ZGRgZAcFVVVRbaQvejSElJWfjbb7+9WbPtdDptInLKSd7qcB3ayp9D7u2P3O/97wzKbCiMUkotFhErMBL4XkQ6K6XM1DyniT8I+g/06tWraN68eZY9e/aEpqSkVO7Zs2dURETEM/fdd99LNcekp6evnDdvXlL9z+bm5va2Wq2ZNdtlZWWtQ0NDt5yOHyISBlwNWEWk5kcYCkSLSHelVMbplNvQUEo5gc9F5HWgP9rztMlp4A9N7mMSEhLyw6JFi3oDlJeXj2zZsuVRGSFsNts3mzdvHgm/P0NPnTp1UUlJyV87d+48tea48vLyfs2bN//2NN0YhTbs0hno4f7rBCxDe642OQlEYyQQgx9GZTUShq+h09LS2h3r/eTk5LezsrL+BixLTU09r/7++++/P73OZsdjlbF06dI4pZRtzJgxp1VDozWt31ZKZdV9U0ReAl4QkfuVUn8IdmBSy2wRqYmVvQe4Tim1SWef/BpD1NBKKZfD4TipWVk1TJgw4dfw8PAVxcXFp30O2dnZSW3atJl6rH1Op/NP/VFKXaKUuu8Y73+qlEowxXx8lFItlVJhSqlGSqkIpVQXpdSHevvl7xhiPXRycnLSZZddFtSsWTPDLND46aefGi1YsCCnIQecM/E/DFFDHzx4sDg3NzdEbz9qcDgc5ObmuoAz6f02MfE5hhB0RUVF2ebNm6t37dp1wimYvsDhcLBq1apGeXl5BZ5YC21i4ksM0SnmzhiZ7XA4Erdt2xaekJCAzWbzqZhcLpeUlJRIbm4uOTk5+QUFBYd9ad/ExBMY4hm6LiISAoRGRkb6NFFkVVWVq6KiwglUuMdFTUz8DsMJ2sTE5PQxxDO0iYmJZzAFbWISQJiCNjEJIP4fIgvGpLLiv+QAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x115e3f5c0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "import sympy\n",
    "\n",
    "\n",
    "from matplotlib_venn import venn3, venn3_circles\n",
    "plt.figure(figsize=(4,4))\n",
    "v = venn2(subsets=(2,2,1), set_labels = ('A', 'B'))\n",
    "\n",
    "c = venn2_circles(subsets=(2, 2, 1), linestyle='dashed')\n",
    "c[0].set_lw(1.0)\n",
    "c[0].set_ls('dotted')\n",
    "plt.title(\"Sample Venn diagram\")\n",
    "plt.annotate('P(AB)', xy=v.get_label_by_id('11').get_position() - np.array([0, 0.05]), xytext=(-70,-70),\n",
    "             ha='center', textcoords='offset points', bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),\n",
    "             arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.5',color='gray'))\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$P(B|A) = \\frac{P(AB)}{P(A)}$<br>\n",
    "$P(A|B) = \\frac{P(AB)}{P(B)}$<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "例題：一個家庭中有兩個小孩，已知至少一個是女孩，問兩個都是女孩的概率是多少？（假設生男生女是等可能的）<br>\n",
    "**解**：由題意可得：樣本空間為\n",
    "    \n",
    "    S = {(兄,弟), (兄,妹),(姐,弟),(姐,妹)}<br>\n",
    "    B = {(兄,妹), (姐,弟),(姐,妹)}<br>\n",
    "    A = {(姐,妹)}<br>\n",
    "    \n",
    "由於，事件 $B$ 已經發生了，所以這時試驗的所有可能只有三種，而事件 $A$ 包含的基本事件只占其中的一種，所以有：$P(A|B) = \\frac{1}{3}$<br>\n",
    "即，在已知至少一個是女孩的請卡滾下，兩個都是女孩的概率為$\\frac{1}{3}$。在這個例子中，如果不知道事件 $B$ 發生，則事件 $A$ 發生的概率為 $P(A) = \\frac{1}{4}$ 這裡的 $P(A) \\neq P(A|B)$，其中的原因在於事件 $B$ 的發生改變了樣本空間，使它由原來的 $S$ 縮減為新的樣本空間 $S_B = B$ "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 隨機變量（Random Variable）\n",
    "\n",
    "在幾乎所有教材裡，介紹概率論都是從事件和樣本空間說起的，但是後面的概率論都是圍繞著隨機變量展開的。可以說前面的事件和樣本空間都是引子，引出了隨機變量這個概率論的核心概念。後面的統計學是建立在概率論的理論基礎之上的，因此可以說理解隨機變量這個概念是學習和運用概率論與數理統計的關鍵。<br>\n",
    "**隨機變量**：<br>\n",
    "\n",
    "* 首先這是一個變量，變量與常數相對，也就是說其取值是不明確的，其實隨機變量的整個取值範圍就是前面說的樣本空間；\n",
    "* 其次這個量是隨機的，也就是說它的去職代有不確定性，讓然是在樣本空間這個範圍內的。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**定義：**\n",
    "> 設隨機試驗的樣本空間是 $S$ ，若對 $S$ 中的每一個樣本點 $e$ ，都有唯一的實數值 $X(e)$ 為隨機變量，間記為 $X$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "隨機變量的定義並不複雜，但是理解起來去不是這麼直觀。\n",
    "\n",
    "* 首先，隨即變量與之前定義的事件是有關係的，因為每個樣本點本身就是一個基本事件；\n",
    "* 在前面隨機試驗結果的表示中提到，無論是數量化的結果還是非數量化的結果，即不管試驗結果是否與數值有關，都可以引入變量，使試驗結果與數建立對應關係；\n",
    "* 隨機變量本質上是一種函數，其目的就是建立試驗結果（樣本中的點，同基本事件$e$）與實數之間的對應關係（例如將“正面”影射為$1$，“反面”影射為$0$）；\n",
    "* 自變量為基本事件$e$，定義域為樣本空間$S$，值域為某個實數集合，多個自變量可以對應同一個函數值，但不允許一個自變量對應多個函數值；\n",
    "* 隨機變量$X$取某個值或某些值就表示某種事件，且具有一定的概率；\n",
    "* 隨機變量中的隨機來源於隨機試驗結果的不確定性。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我們可以通過引入隨機變量，我們簡化了隨機試驗結果（事件）的表示，從而可以更加方便的對隨機試驗進行研究。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**隨機變量的分類**:<br>\n",
    "* 離散隨機變量；\n",
    "* 連續隨機變量；\n",
    "* 每類隨機變量都有其獨特的概率密度函數和概率分佈函數。\n",
    "\n",
    "**隨機變量的數字特徵**：<br>\n",
    "* 期望（均值），眾數，分位數，中位數；\n",
    "* 方差；\n",
    "* 協方差；\n",
    "* 相關係數。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 隨機變量（Random Variable）\n",
    "\n",
    "*對隨機變量以及其取值規律的研究是概率的核心內容。在上一個小結中，總結了隨機變量的概念以及隨機變量與事件的聯繫。這個小結會更加深入的討論隨機變量。*\n",
    "\n",
    "#### 隨機變量與事件\n",
    "\n",
    "隨機變量的本質是一種函數（映射關係），在古典概率模型中，“事件和事件的概率”是核心概念；但是在現代概率論中，“隨機變量及其取值規律”是核心概念。\n",
    "<br>\n",
    "**隨機變量與事件的聯繫與區別**\n",
    "<br>\n",
    "小結 1 中對著練歌概念的聯繫進行了非常詳細的描述。隨機變量實際上只是事件的另一種表達方式，這種表達方式更加的形式化和符號化，也更佳便於理解以及進行邏輯運算。不同的事件，其實就是隨機變量不同取值的組合。在陈希孺先生的書中，有一個很好的例子來說明這兩者的區別：<br>\n",
    "> 對於隨機試驗，我們所關心的往往是與所研究的特定問題有關的某個或某些變量，而這些量就是隨機變量。當然，有事我們所關心的是某個或某些特定的隨機時間。例如，在特定一群人中，年收入在萬元以上的高收入者，以及年收入在$3000$元以下的低收入者，各自比率如何？者看上去是兩個孤立的事件。可是當我們引入一個隨機變量$X$： \n",
    "> \n",
    "> <br>\n",
    "> <center> $X = $ 隨機抽出一個人其年收入</center>\n",
    "> <br>\n",
    "> \n",
    ">則$X$是我們關心的隨機變量。上述兩個事件可以分表表示為$\\{X > 10000\\}$或$\\{X < 3000\\}$。這就看出：**隨機事件**這個概念實際上包容在**隨機變量**這個更廣的概念之中。也就是說，隨機事件是靜態的觀點來研究隨機現象，而隨機變量則是一種動態的觀點。「概率論能從計算一些孤立事件的概率發展成為一個更高的理論體系，其根本概念就是隨機變量\n",
    "\n",
    "*這段話，非常清楚的解釋了隨機變量與事件的區別：就跟變量和常量之間的區別那樣*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 隨機變量的分類（The Classification of the Random Variable）\n",
    "\n",
    "**隨機變量從其可能的取值的性質分為兩大類：離散型隨機變量（Discrete Random Variable）和連續性隨機變量（Continuous Random Variable）**<br>\n",
    "##### 離散型隨機變量（Discrete Random Variable）\n",
    "\n",
    "離散型隨機變量的取值在整個實數軸上是有間隔的，要麼只有有限個取值，要麼就是無限可數。<br>\n",
    "如下圖："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[  1.   2.   3.   4.   5.   6.   7.   8.   9.  10.  11.  12.  13.  14.  15.\n",
      "  16.  17.]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEICAYAAACuxNj9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3X2clHW9//HXG0gQ17xZ1lJA8V5B0Wo1pEzQSg2THqZJoXnX8QjZjXUwuxM0PSWckx5/CuVJzbxJPdgNBWWlpzx2RFktMTQKkCPg3YKKbroq8vn9cV0LwzC7M7s7187szvv5eMxjZr7XdX3ns7Mz87m+N9d1KSIwMzPrSL9KB2BmZtXPycLMzIpysjAzs6KcLMzMrCgnCzMzK8rJwszMinKy6CMkbSvpF5LWS/qvMt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nCZcXjSl0JXAhUZEZPO3FNAb4TEa+n6zzf44F1gpNFBiSNAN4FPFjZSDa5iuSLsrHSgeTYE2gGbky7x34gabtKBxURa0j28J4CngHWR8RvKhvVVt4REc+kj58F3lHJYNpxNvCrSgcBIGkisCYiHq10LHn2A46U9KCkP0g6rNIBdcTJoswk1QF3AV+MiJerIJ4TgOcj4uFKx5JnAPBuYE5EvAv4B5XpTtlC2v8/kSSZ7QZsJ+m0ykbVvvQyxFU1/13S10m6ZW+tglgGA18DLq50LAUMAHYm6baeBtwpSZUNqX1OFmUk6W0kieLWiPhJpeNJvQ84UdJK4HbgaEm3VDYkAFYDqyOirfU1lyR5VNoHgScjojki3gR+AoytcEz5npO0K0B6XzXdF5LOBE4AJkd1HMS1N0nifzT9DgwDHpH0zopGlVgN/CQSD5G0/Ht88L1UThZlku4RXA88ERHfrXQ8bSLiqxExLCJGkAzU3hsRFd9TjohngVWS9k+LjiG55nqlPQWMkTQ4/Z8eQxUMvOeZB5yRPj4D+HkFY9lE0nEk3Z0nRsSrlY4HICIei4hdImJE+h1YDbw7/fxV2s+A8QCS9gO2oTrOQluQk0X5vA84nWTP/c/p7SOVDqrKfQ64VdJi4FDgXyscD2lLZy7wCPAYyXekYqdlkPRj4AFgf0mrJZ0DfAf4kKS/k7SEvlMlcV0DbA/8Nv38f69K4qq4duK6AdgrnU57O3BGlbTGCvLpPszMrCi3LMzMrCgnCzMzK8rJwszMinKyMDOzopwszMysKCcLMzMrysnCzMyK+v8HcPiaINkjCgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x11681f588>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from scipy import stats\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def poisson_pmf(mu=3):\n",
    "    \n",
    "    poisson_dis = stats.poisson(mu)\n",
    "    x = np.arange(poisson_dis.ppf(0.001), poisson_dis.ppf(0.999))\n",
    "    print(x)\n",
    "    \n",
    "    fig, ax = plt.subplots(1, 1)\n",
    "    ax.plot(x, poisson_dis.pmf(x), 'bo', ms=8, label='poisson pmf')\n",
    "    ax.vlines(x, 0, poisson_dis.pmf(x), colors='b', lw=5, alpha=0.5)\n",
    "    ax.legend(loc='best', frameon=False)\n",
    "    plt.ylabel('Probability')\n",
    "    plt.title('PMF of poisson distribution(mu={}) - plot three'.format(mu))\n",
    "    plt.show()\n",
    " \n",
    "poisson_pmf(mu=8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[  4.   5.   6.   7.   8.   9.  10.  11.  12.  13.  14.  15.  16.  17.  18.]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZIAAAEICAYAAAB1f3LfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAAIABJREFUeJzt3XmcVNWd9/HPFwSUqLhAjBGwNRojihpFYhaXaBaciPg4uHbcDaMZsz5jouFxiZFsZsZsZsENlzZoTFQmwTHOGJwxowZQokFjggoIbsQtRuJC+D1/nNNYFFVd1V19u7qb7/v1uq+699xzT/1q/dU551aVIgIzM7OuGtDsAMzMrG9zIjEzs4Y4kZiZWUOcSMzMrCFOJGZm1hAnEjMza4gTSS8laSNJ/y7pJUk/rbD/fEnXdnD8QkkHFBpkg9crKSTtUGfdNbdX0mhJf5U0sIFQS9v+kaRz8voBkpZ1R7u5vX0lPdKN7f1E0mHd1d76RtKnJH2jwPZb8vN6g25qbydJCyS9LOnT3dFmEZxISkhaLOlv+U3qGUkzJG2c983JT5Ddy465KZcfkLfPl/RGbqN9+UIXwpkMbAVsGRFHdPbgiNglIuZ04Xob0hPXGxFLI2LjiPh7R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SppL+ZbSt2bFUImko8CXSsEtfsQGwBbAPcCZwgyQ1N6SqTgc+FxGjgM+RRy26mxNJZe8HDpW0GJgJHCjp2uaG1KFlwLKIuDdv30hKLL3Vh4DHI2JFRLwB/Bx4X5NjquUZSVsD5MteMZzREUknAocArdF7vzD2DtIHit/l19tI4D5Jb2tqVB1bBvw8kt+SRi16zQkCZU4gvb4Afgp4sr2nRMTZETEyIlpIk8B3RESv/cQcEU8DT0jaKRcdRPq/+95qKbCPpKH5k9xB9OKTA7JZpBcl+fKWJsZSk6QJpKHZQyNiZbPjqSYiHoyIt0ZES369LQP2zM/p3upm4IMAkt4JDKb3/hrwk8D+ef1A4E9FXMkGRTRqTfEpoE3SYOAx4KQmx1NVRNwr6UbgPtKwy/30op+dkPQT4ABguKRlwHnA10lDGKeQ/pLgyOZFuLYq8Z4NDAFuz6Mu90TEaU0LMqsUa0QUMtzSHarct1cAV+TTbF8HTugNPb4qsX4C+E4+qeVVYEoh190Lbr+ZmfVhHtoyM7OGOJGYmVlDnEjMzKwhTiRmZtYQJxIzM2uIE4mZmTXEicTMzBry/wHfB0irPM4H/gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1168b1470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def binom_pmf(n=1, p=0.1):\n",
    "    binom_dis = stats.binom(n, p)\n",
    "    x = np.arange(binom_dis.ppf(0.0001), binom_dis.ppf(0.9999))\n",
    "    print(x)  \n",
    "    \n",
    "    fig, ax = plt.subplots(1, 1)\n",
    "    ax.plot(x, binom_dis.pmf(x), 'bo', label='binom pmf')\n",
    "    ax.vlines(x, 0, binom_dis.pmf(x), colors='b', lw=5, alpha=0.5)\n",
    "    ax.legend(loc='best', frameon=False)\n",
    "    plt.ylabel('Probability')\n",
    "    plt.title('PMF of binomial distribution(n={}, p={}) - plot four'.format(n, p))\n",
    "    \n",
    "    plt.show()\n",
    "    \n",
    "\n",
    "binom_pmf(n=20, p=0.6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Plot three 是 Poisson Distribution\n",
    "* Plot four 是 Binomal Distribution\n",
    "\n",
    "常見的**離散型隨機變量**包括以下這幾種：<br>\n",
    "\n",
    "* 0-1分佈（Bernoulli Distribution）\n",
    "* 二項分布（Binomial Distribution）\n",
    "* 幾何分佈（Geometric Distribution）\n",
    "* 泊松分佈（Poisson Distribution）\n",
    "* 超幾何分佈（Hyper-geometric Distribution）\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 連續型隨機變量（Continuous Random Variable）\n",
    "\n",
    "連續型隨機變量的取值要麼包括了整個實數集$(-\\infty, \\infty)$，要麼在一個區間內連續，總之，這一類的隨機變量的可能取值要比離散型隨機變量的取值多得多，個數是無窮不可數的。<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**常見的連續型隨機變量包括以下幾種**：<br>\n",
    "\n",
    "* 均勻分布\n",
    "* 指數分佈\n",
    "* 正太分佈（$\\gamma$分佈， $\\beta$分佈，$\\chi^2$分佈等）\n",
    "\n",
    "##### 概率密度函數的性質\n",
    "\n",
    "所有的概率密度函數$f(x)$都滿足一下的兩條性質；所有滿足下面兩條性質的一元函數也都可以作為概率密度函數。<br>\n",
    "$f(x) \\geq 0$，以及$\\int_{-\\infty}^{+\\infty}f(x)dx = 1$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 隨機變量的基本性質\n",
    "\n",
    "隨機變量最主要的性質是其所有可能取到的這些值的取值規律，即取到的概率大小。如果我們把一個隨機變量的所有可能的取值的規律都研究透徹了，那麼這個隨機變量也就研究透徹了。隨機案變量的性質只要有兩類：一類是大而全的性質，這類性質可以詳細描述所有可能取值的概率，律如**累積分佈函數（Cumulative Distribution Funtion）**和**概率密度函數（Probability Density Function）**；另一類是找到該隨機變量的一些特徵或者代表值，例如隨機變量的方差或者期望等數字特徵。常見的隨機變量的性質如下表：\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|    name    | 解釋 |\n",
    "| :---: | :---: |\n",
    "| CDF: Cumulative Distribution Function |  連續型和離散型隨機變量都有，一般以$F(X)$表示 |\n",
    "| PDF: Probability Density Function    |  連續型隨機變量在各點的取值規律，用$f(x)$表示 |\n",
    "| PDF: Probability Density Function    |  連續型隨機變量在各點的取值規律，用$f(x)$表示 |\n",
    "| PMF: Probability Mass Function    |  離散型型隨機變量在各特定取值上的概率 |\n",
    "| RVS: Random Variate Sample    |  從一個給定分佈取樣 |\n",
    "| PPF: Percentile Point Function  |  CDF 的反函數 |\n",
    "| IQR: Inter Quartile Range   |  $25%$分位數與$75%$ 分位數之差 |"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*PDF 只有**連續型隨機變量**才有， PMF 只有**離散型隨機變量**才有；一個分佈的 CDF 求導等於 PDF， 一個分佈的 PDF 積分後就是 CDF*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一位離散型隨機變量及其 Python 實現\n",
    "\n",
    "上一小節，對隨機變量做了一個概述，這一節主要紀錄以為離散變量以及關於他們的一些性質。對於概率論與數理統計方面的計算以及可視化，主要的`pyhton`包有`scipy`，`numpy`和`matplotlib`等。<br>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from scipy import stats\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`scipy` 是 `python` 中使用最為廣泛的科學計算工具包，在加上`numpy`和`matplotlib`，基本可以處理大多數的計算和作圖任務。下面是`wikipedia`對`scipy`的介紹：<br>\n",
    "\n",
    "> SciPy是一个开源的Python算法库和数学工具包。SciPy包含的模块有最优化、线性代数、积分、插值、特殊函数、快速傅里叶变换、信号处理和图像处理、常微分方程求解和其他科学与工程中常用的计算。与其功能相类似的软件还有MATLAB、GNU Octave和Scilab。SciPy目前在BSD许可证下发布。它的开发由Enthought资助。\n",
    "\n",
    "我們使用的是 `scipy`中的 `stats`模塊，這個模塊包歡樂概率論以及統計相關的函數。\n",
    "相關函數可以查詢：<a href=\"https://docs.scipy.org/doc/scipy/reference/tutorial/stats.html\"> scipy stats</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "####  伯努利分佈（Bernoulli Distribution）\n",
    "\n",
    "又名兩點分佈或者$0-1$分佈，是一個離散型概率分佈。若伯努利試驗成功，則伯努利隨機變量取值為$1$，如果失敗則取值為$0$。記其成功概率為$p(0\\leq p \\leq 1)$，失敗概率為：$q = 1-p$。其概率質量函數（PMF） 為：<br>\n",
    "<center>\n",
    "    $\\begin{equation}     \\nonumber P_X(x) = \\left\\{     \\begin{array}{l l}     p& \\quad \\text{for  } x=1\\\\     1-p & \\quad \\text{ for } x=0\\\\     0  & \\quad \\text{ otherwise }     \\end{array} \\right. \\end{equation}$\n",
    "    </center>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEICAYAAACktLTqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAFwFJREFUeJzt3X+QXeV52PHvo98SYAuBmBhpZXAisKlxI3uL8dBpHdspP9ICpY4jJiQhJVCSkPxhl1bUieshTmHMtGlc0xglxcSe2oAdRpETedSJweOWGIqoHDCiagXB6IdjZEC4BN2re3ef/nHPisuy0t5drvae++r7mdmZ8+Pdc59Xuzz78J73vCcyE0lSWeYNOgBJUv+Z3CWpQCZ3SSqQyV2SCmRyl6QCmdwlqUAmdw1ERDwTER8adBzTiYirI+J/dO1nRPxEtf25iPjtOYrjgoj4vxHxckRcPhefqeG2YNABSMMqM6+fw4+7GfhsZv7+HH6mhpiVu4ZaRBwvBcpbgScGHYSGh8ld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
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from scipy.stats import bernoulli\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "fig, ax = plt.subplots(1, 1)\n",
    "\n",
    "p = 0.8\n",
    "x = np.linspace(0,1)\n",
    "\n",
    "plt.plot(x,bernoulli.pmf(x,p),'o-',label='bernoulli pmf')\n",
    "\n",
    "plt.title('bernoulli pmf')\n",
    "plt.xlim(-0.1,1.1)\n",
    "plt.ylim(0,1)\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "伯努利分佈只有一個參數$p$，記做$X ~ Bernuolli(p)$，或$X ~ B(1,p)$，讀做$X$服從參數為$p$的伯努利分佈。伯努利分佈適合於試驗結果只有兩種可能的單次試驗。例如拋一次硬幣，其結果只有正面或者反面兩種可能；一次產品質量檢測，結果只有合格還是不合格這兩種可能。<br>\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEICAYAAACwDehOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAFpxJREFUeJzt3X20XXV95/H3xyAFBaUD11ryYNIaH6K10l7ANa5ROmoNsAhdPiaVsXSwmc4afBhrFR3LWOpqkdaHsU1nTNERHwNia0ONK+oojrRoE8TaCTQ2jbS5TasRwQdsheh3/jj7bg+Hc+859+bu3ATer7XOyn747d/5no2ez92/vc/eqSokSQJ40GIXIEk6chgKkqSWoSBJahkKkqSWoSBJahkKkqSWoaAjRpLjk1yX5JtJPjRk/RuSvG8xapurJJXk0c30u5O8sZn+d0l2z6Gf65O8pJl+UZKPL2CNu5Kc1Uwv6L5N8rokVy5Ufzp8DIUHuCS3JfmXJN9J8tUk/zvJCc2665svt58e2OYjzfKzmvk3JLmn6WP69ep5lPM84MeAk6vq+Yf62Y5EVf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Vm6tqsqomJyYmDrEsSdJMugyFKWB53/wyYH+H7ydJOkRdhsIOYHWSVUmOBdYDWzt8P0nSIeosFKrqIHAxsB24FbimqnYluSzJOoAkpyeZAp4PvCPJrq7qkSSN1uXVR1TVNmDbwLJL+6Z30BtWkiQdAfxFsySpZShIklqGgiSpZShIklqGgiSpZShIklqGgiSpZShIklqGgiSpZShIklqGgiSpZShIklqGgiSpZShIklqGgiSpZShIklqGgiSp1WkoJFmbZHeSPUkuGbL+R5Jc3az/fJKVXdYjSZpdZ6GQZAmwCTgbWANsSLJmoNlFwB1V9WjgrcCbuqpHkjRal0cKZwB7qmpvVd0NbAHOH2hzPnBVM30t8Iwk6bAmSdIsjumw76XAvr75KeDMmdpU1cEk3wROBr7e3yjJRmBjM/udJLs7qXjuTmGg1kMRj5Ok+5sj6TviUeM06jIUhv3FX/NoQ1VtBjYvRFELKcnOqppc7DokHZmOxu+ILoePpoDlffPLgP0ztUlyDPBw4Bsd1iRJmkWXobADWJ1kVZJjgfXA1oE2W4FfaqafB3yqqu5zpCBJOjw6Gz5qzhFcDGwHlgDvqqpdSS4DdlbVVuCdwHuT7KF3hLC+q3o6csQNaUk6ohx13xHxD3NJ0jR/0SxJahkKkqSWoTBPo27hIemBK8m7knwtyf9b7FrmylCYhzFv4SHpgevdwNrFLmI+DIX5GecWHpIeoKrq/3KU/ubKUJifYbfwWLpItUjSgjEU5mes23NI0tHGUJifcW7hIUlHHUNhfsa5hYckHXUMhXmoqoPA9C08bgWuqapdi1uVpCNFkg8CNwKPTTKV5KLFrmlc3uZCktTySEGS1DIUJEktQ0GS1DIUJEktQ0GS1DIUJEktQ0GS1Pr/edWzAZPvTq8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x68640dd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import scipy.stats as stats\n",
    "from scipy.stats import bernoulli\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def bernoulli_pmf(p=0.0):\n",
    "\n",
    "    ber_dist = stats.bernoulli(p)\n",
    "    x = [0, 1]\n",
    "    x_name = ['0', '1']\n",
    "    pmf = [ber_dist.pmf(x[0]), ber_dist.pmf(x[1])]\n",
    "    plt.bar(x, pmf, width=0.15)\n",
    "    plt.xticks(x, x_name)\n",
    "    plt.ylabel('Probability')\n",
    "    plt.title('PMF of bernoulli distribution')\n",
    "    plt.show()\n",
    "\n",
    "bernoulli_pmf(p=0.8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "上面兩幅圖都是表示伯努利分佈的 PMF；我們為了得到比較準確的某個服從伯努利分佈的隨機變量的期望，需要大量重複伯努利試驗，例如重複$n$次，然後利用$\\frac{正面朝上的次數}{n}$來估計$p$值，當我們重複$n$次以後，這就變成了二項分布，就是下面會提到的**二項分布**。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 二项分布（Binomial Distribution）\n",
    "\n",
    "二項分布是指$n$個獨立的是/非試驗中成功的次數的離散概率分佈，其中每次試驗的成功概率為$p$。這樣的單詞成功/失敗試驗又稱為伯努利試驗。實際上，當$n = 1$時，二項分布就是伯努利分佈。二項分布時顯著性差異的二項試驗的基礎。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD8CAYAAACb4nSYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAG4FJREFUeJzt3X+UVXX97/HnixmBaPyaX5jVLWD44ZcMDAOdL+GPa5KWkAjVxcLUC6GLBmV9u7qavnhtOUq1bl+m5e16A8kUsVJQo6XzLVqaZXVZSTIEaeAPBiJEuvnziqSj38H3/eNs6HAYmD0zZ86ZYb8ea5119v7sz97nfTac19mz9z57KyIwM7Ns6FfuAszMrHQc+mZmGeLQNzPLEIe+mVmGOPTNzDLEoW9mliEOfTOzDHHom5lli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Ossec3/B/wKmFowqRyfyQ7rKtNn8ixghqSd5HYDf0zSDwv69Nj66ouh350btZe1roJ9vjPI7ZPtDZqA/5qckTIZeC0i/lLuoiT9pwP7MSVNIvf/9eUSvK7I3ff5qYi4+QjdSr7O0tRVjnUmqVrSe5LhdwHnA08XdCv5ZzJNXeX4TEbEdRExLCJGksuJX0bEZQXdemx9dXhj9N4munGj9l5Q179ImkHuJvGvkDtzoMdJWkXurI4hknYDDeQOahERy4G15M5GaQHeAL7QS+qaBSyQ1Aa8CcwuwZc35LbELgeeTPYHA/x3oCavtnKsszR1lWOdvQ+4S1IFuS+Z+yLiJ+X+TKasqyyfyfaUan35F7lmZhnSF3fvmJlZFzn0zcwyxKFvZpYhDn0zswxx6JuZZYhD38wsQxz6ZmYZ4tA3M8uQ/w8ykNNW52qhwgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x684f6190>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from scipy.stats import binom\n",
    "import matplotlib.pyplot as plt\n",
    "fig, ax = plt.subplots(1, 1)\n",
    "\n",
    "n, p = 5, 0.4\n",
    "mean, var, skew, kurt = binom.stats(n, p, moments='mvsk')\n",
    "\n",
    "x = np.arange(binom.ppf(0.01, n, p),\n",
    "              binom.ppf(0.99, n, p))\n",
    "ax.plot(x, binom.pmf(x, n, p), 'bo', ms=8, label='binom pmf')\n",
    "ax.vlines(x, 0, binom.pmf(x, n, p), colors='b', lw=5, alpha=0.5)\n",
    "\n",
    "rv = binom(n, p)\n",
    "ax.vlines(x, 0, rv.pmf(x), colors='k', linestyles='-', lw=1,\n",
    "        label='frozen pmf')\n",
    "ax.legend(loc='best', frameon=False)\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
